package com.atlanova;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

public class BanksInfoActivity extends Activity {

    String[] banks = {"ПриватБанк", "Укрсоцбанк(uniCredit)", "Укрэксимбанк", "Аваль", "Кредобанк", "Марфин Банк",
            "Правэкс-Банк", "Профин банк", "ПУМБ", "Укргазбанк", "Укринбанк", "УкрСиббанк"};
    Integer[] banks_icons = {R.drawable.privat, R.drawable.unicredit, R.drawable.exim, R.drawable.aval, R.drawable.kredo, R.drawable.marfin,
            R.drawable.pravex, R.drawable.profin, R.drawable.pumb, R.drawable.ukrgas, R.drawable.ukrin, R.drawable.ukrsib};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_banks_info);

        ListView listView = (ListView) findViewById(R.id.listView);

        BIAdapter adapter = new BIAdapter(this,
                R.layout.row_banks_info, banks);

        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(getApplicationContext(), BankActivity.class);
                intent.putExtra("selectedBank", position);
                startActivity(intent);
            }
        });


    }

    public class BIAdapter extends ArrayAdapter<String> {

        public BIAdapter(Context context, int textViewResourceId,
                         String[] objects) {
            super(context, textViewResourceId, objects);
            // TODO Auto-generated constructor stub
        }

        @Override
        public View getDropDownView(int position, View convertView,
                                    ViewGroup parent) {
            // TODO Auto-generated method stub
            return getCustomView(position, convertView, parent);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            return getCustomView(position, convertView, parent);
        }

        public View getCustomView(int position, View convertView,
                                  ViewGroup parent) {
            // TODO Auto-generated method stub

            LayoutInflater inflater = getLayoutInflater();
            View row = inflater.inflate(R.layout.row_banks_info, parent, false);
            TextView label = (TextView) row.findViewById(R.id.bank);
            label.setText(banks[position]);

            ImageView icon = (ImageView) row.findViewById(R.id.icon);
            icon.setImageResource(banks_icons[position]);

            return row;
        }
    }

}

